package com.skplanet.oneplusonewindow.moimserver.domain;

import java.io.Serializable;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "MOIM_PLAZA")
public class Moim_Plaza  implements Serializable{


	public String getRegdate() {
		return regdate;
	}

	public void setRegdate(String regdate) {
		this.regdate = regdate;
	}

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name = "title")
	private String title;
	
	@Column(name = "regdate")
	private String regdate;

	@Column(name = "content")
	private String content;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "moim2_id")
	@JsonIgnore
	private Moim_Moim moim2;
	
	@OneToMany(mappedBy = "plaza", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Moim_PlazaBoard> plazaboards;
	
	
	public Moim_Plaza() {
		Date date = new Date();
		DateFormat format1 = DateFormat.getDateInstance(DateFormat.MEDIUM);
		setRegdate(format1.format(date));
	}

	public Moim_Moim getMoim2() {
		return moim2;
	}

	public void setMoim2(Moim_Moim moim) {
		this.moim2 = moim;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	public List<Moim_PlazaBoard> getPlazaboards() {
		return plazaboards;
	}

	public void setPlazaboards(List<Moim_PlazaBoard> plazaboards) {
		this.plazaboards = plazaboards;
	}
	
	public void addPlazaboard(Moim_PlazaBoard plazaboard) {
		if(this.plazaboards == null) {
			this.plazaboards = new ArrayList<Moim_PlazaBoard>();
			this.plazaboards.add(plazaboard);
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

		
}
